package com.hefu.virtuallife.ui.ticket;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.RelativeLayout;

import com.hefu.virtuallife.R;
import com.hefu.virtuallife.bean.TrainTicketBean;
import com.hefu.virtuallife.ui.VoiceActivity;
import com.hefu.virtuallife.utils.UiUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by pc on 2018/8/10.
 */

public class BookingHistoryActivity extends VoiceActivity {

    @BindView(R.id.tab)
    TabLayout tab_layout;
    @BindView(R.id.viewPager)
    ViewPager vp;
//    @BindView(R.id.rl_ticketinfo)
//    RelativeLayout rl_ticketinfo;
    private List<TicketInfoListFragment> fragments;


    @Override
    protected int setLayoutId() {
        return R.layout.activity_booking_history;
    }

    @Override
    protected void initVariables(@Nullable Bundle savedInstanceState) {
        fragments = new ArrayList<>();
        fragments.add(TicketInfoListFragment.newInstance("1"));
        fragments.add(TicketInfoListFragment.newInstance("2"));
        fragments.add(TicketInfoListFragment.newInstance("3"));
        FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }
        };
        vp.setOffscreenPageLimit(3);
        vp.setAdapter(adapter);
        tab_layout.setupWithViewPager(vp);

        tab_layout.setTabMode(TabLayout.MODE_FIXED);
        TabLayout.Tab tab1 = tab_layout.newTab();
        TabLayout.Tab tab2 = tab_layout.newTab();
        TabLayout.Tab tab3 = tab_layout.newTab();
        tab_layout.addTab(tab1);
        tab_layout.addTab(tab2);
        tab_layout.addTab(tab3);
        tab_layout.setupWithViewPager(vp);

        final String[] bookHistory = UiUtils.getStringArray(R.array.book_history);
        for(int i=0;i<bookHistory.length;i++){
            tab_layout.getTabAt(i).setText(bookHistory[i]);
        }

    }

    @Override
    protected void onResume() {
        super.onResume();
        fillData();
    }

    @Override
    protected void uiProcess() {

    }

    @OnClick(R.id.img_return)
    protected void onFinishClick() {
        finish();
    }

    private void fillData(){
        List<TrainTicketBean> list = getData();
        for (TicketInfoListFragment fragment : fragments){
            fragment.initData(list);
        }
    }

    public List<TrainTicketBean> getData() {
        List<TrainTicketBean> list = new ArrayList<TrainTicketBean>();
        TrainTicketBean bean = new TrainTicketBean("D636", "06:33","14小时28分钟","21:01","一等：无","二等：无","无座：有","上海虹桥","成都东");
        list.add(bean);

        return list;
    }
}
